"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var common_1 = require("@angular/common");
var moment = require('moment');
var RYDateService = /** @class */ (function () {
    function RYDateService() {
    }
    //
    RYDateService.timeline = function (datestamp) {
        //ECMAScript5新增了now()方法，该方法返回当前时间距离1970年1月1日0点UTC的毫秒数。该方法不支持传递参数
        var second = parseInt(datestamp);
        if (isNaN(second) || second <= 0) {
            return this.useZh ? "无法获取数据" : "Unable to obtain data";
        }
        var nowstamp = Date.now();
        var distance = parseInt(((nowstamp - second * 1000) / 1000).toString()); //单位转换成秒
        /**
         * UE Updated.
         * 24小时以内：更新于**点**分
         * 超过24小时：更新于*天前
         */
        if (distance < 60 * 60 * 24) {
            return this.useZh ? RYDateService.dateString((second * 1000).toFixed(), "更新于HH点mm分") : (RYDateService.dateString((second * 1000).toFixed(), "HH:mm") + " updated");
        }
        else {
            return this.useZh ? ("更新于 " + (distance / 60 / 60 / 24).toFixed() + " 天前") : ((distance / 60 / 60 / 24).toFixed() + " days ago");
        }
    };
    RYDateService.dateString = function (datestamp, format) {
        //时间戳以毫秒为单位
        var millisecond = parseInt(datestamp);
        if (isNaN(millisecond)) {
            return "";
        }
        var date = new Date(millisecond);
        var datePipe = new common_1.DatePipe("en-US");
        var dateStr = datePipe.transform(date, format);
        return dateStr;
    };
    RYDateService.dateToString = function (date, format) {
        if (date == undefined) {
            return "";
        }
        return moment(date).format(format);
    };
    RYDateService.dateFromString = function (dateStr, format) {
        if (dateStr == undefined) {
            return null;
        }
        if (dateStr.length == 0) {
            return null;
        }
        return moment(dateStr, format);
    };
    RYDateService.weekday = function (datestamp) {
        //时间戳以毫秒为单位
        var millisecond = parseInt(datestamp);
        if (isNaN(millisecond)) {
            return "";
        }
        var date = new Date(millisecond);
        var weekday = date.getDay();
        switch (weekday) {
            case 0: return this.useZh ? "周日" : "Sun";
            case 1: return this.useZh ? "周一" : "Mon";
            case 2: return this.useZh ? "周二" : "Tue";
            case 3: return this.useZh ? "周三" : "Wed";
            case 4: return this.useZh ? "周四" : "Thu";
            case 5: return this.useZh ? "周五" : "Fri";
            case 6: return this.useZh ? "周六" : "Sat";
            default: return this.useZh ? "未知" : "Unknown";
        }
    };
    RYDateService.hour = function (datestamp) {
        var millisecond = parseInt(datestamp);
        if (isNaN(millisecond)) {
            return "";
        }
        var date = new Date(millisecond);
        return date.getHours().toString() + (this.useZh ? "点" : ":00");
    };
    RYDateService.useZh = false;
    return RYDateService;
}());
exports.RYDateService = RYDateService;
